//StudybarCommentBegin
#include <stdio.h>
int main()
{
    int* pmax, * pmin;
    int data[10], temp, i, n;
    //    printf("enter n:");
    scanf("%d", &n);
    //    printf("enter %d data:",n);
    for (i = 0; i < n; i++)
        scanf("%d", &data[i]);
    printf("orgin:");
    for (i = 0; i < n; i++)
        printf("%4d", data[i]);
    printf("\n");
    //StudybarCommentEnd
    pmax = pmin = data;//
   
    for (i = 1; i < n; i++) {
        if (data[i] > *pmax)
            pmax = data+i;//
        if (data[i] < *pmin)
            pmin=data+i;//
    }
    temp = data[0];
    data[0] = *pmax;
    *pmax = temp;

    temp = data[n - 1];
    data[n - 1] = *pmin;
    *pmin = temp;

    //StudybarCommentBegin
    printf("sorted:");
    for (i = 0; i < n; i++)
        printf("%4d", data[i]);
    printf("\n");

}
//StudybarCommentEnd